﻿// <copyright file="_SOFTFS_IND_FILE_BLOCK_ROOT_DATA.cs" company="Sinclair Community College">
// Copyright 2010 Sinclair Community College
// </copyright>
// <originalAuthor>Patrick S. Seymour (patrick.seymour@gmail.com)</originalAuthor>

namespace SinclairCC.AppV
{
    using System;

    /// <summary>
    /// The Run-File container maintains a data index table.
    /// </summary>
    public class _SOFTFS_IND_FILE_BLOCK_ROOT_DATA
    {
        /// <summary>
        /// Array (size 20) of storage indexes (4 bytes each) that reference storage blocks that
        /// describe the first segment of the file, up to 80 KB by default.
        /// </summary>
        private uint[] fileDataTable;

        /// <summary>
        /// An index to a storage block which contains an array of storage indexes (maximum 1,024)
        /// that describe second segment, up to 4 MB.
        /// </summary>
        private uint indirectionTableIndex;

        /// <summary>
        /// An index to a storage block which contains an array of storage indexes (up to 1,024).
        /// Each of the indexes points to another storage block of data indexes which point to the
        /// actual data blocks. Using this index, the maximum addressable data size is 4 GB.
        /// </summary>
        private uint doubleIndirectionTableIndex;

        /// <summary>
        /// Another indirection layer on top of the double indirection table index by which the
        /// maximum addressable data size is 4 TB.
        /// </summary>
        private uint tripleIndirectionTableIndex;

        /// <summary>
        /// Initializes a new instance of the _SOFTFS_IND_FILE_BLOCK_ROOT_DATA class.
        /// </summary>
        public _SOFTFS_IND_FILE_BLOCK_ROOT_DATA(System.IO.BinaryReader fileReader)
        {
            // The file data table is 20 entries long.
            this.fileDataTable = new uint[20];

            for (int i = 0; i < this.fileDataTable.Length; i++)
            {
                this.fileDataTable[i] = fileReader.ReadUInt32();
            }
            this.indirectionTableIndex = fileReader.ReadUInt32();
            this.doubleIndirectionTableIndex = fileReader.ReadUInt32();
            this.tripleIndirectionTableIndex = fileReader.ReadUInt32();
        }

        public uint[] FileDataTable
        {
            get { return this.fileDataTable; }
        }

        /// <summary>
        /// An index to a storage block which contains an array of storage indexes (maximum 1,024)
        /// that describe second segment, up to 4 MB.
        /// </summary>
        public uint IndirectionTableIndex
        {
            get { return this.indirectionTableIndex; }
        }

        /// <summary>
        /// An index to a storage block which contains an array of storage indexes (up to 1,024).
        /// Each of the indexes points to another storage block of data indexes which point to the
        /// actual data blocks. Using this index, the maximum addressable data size is 4 GB.
        /// </summary>
        public uint DoubleIndirectionTableIndex
        {
            get { return this.doubleIndirectionTableIndex; }
        }

        /// <summary>
        /// Another indirection layer on top of the double indirection table index by which the
        /// maximum addressable data size is 4 TB.
        /// </summary>
        public uint TripleIndirectionTableIndex
        {
            get { return this.tripleIndirectionTableIndex; }
        }
    }
}
